package cn.stylefeng.guns.modular.hx.storage.controller;

import cn.stylefeng.guns.core.util.DateUtil;
import cn.stylefeng.guns.modular.basic.entity.BasicWarehouse;
import cn.stylefeng.guns.modular.basic.model.params.BasicWarehouseParam;
import cn.stylefeng.guns.modular.basic.model.result.BasicWarehouseResult;
import cn.stylefeng.guns.modular.basic.service.BasicWarehouseService;
import cn.stylefeng.guns.modular.hx.storage.entity.HxStorageStock;
import cn.stylefeng.guns.modular.hx.storage.service.HxStorageStockService;
import cn.stylefeng.guns.modular.hx.storage.entity.HxStorageOut;
import cn.stylefeng.guns.modular.hx.storage.model.params.HxStorageOutDetailedParam;
import cn.stylefeng.guns.modular.hx.storage.model.params.HxStoragePutDetailedParam;
import cn.stylefeng.guns.modular.hx.storage.model.result.*;
import cn.stylefeng.guns.modular.hx.storage.service.HxStorageOutService;
import cn.stylefeng.guns.modular.hx.storage.service.HxStoragePutDetailedService;
import cn.stylefeng.guns.modular.hx.storage.service.HxStorageOutDetailedService;
import cn.stylefeng.guns.modular.hx.storage.service.HxStoragePutService;
import cn.stylefeng.guns.modular.hx.storage.service.HxStorageOffShelfService;
import cn.stylefeng.guns.modular.order.service.OrderTransportService;
import cn.stylefeng.guns.modular.transport.model.params.TDispatchParam;
import cn.stylefeng.guns.modular.transport.model.params.TransportMsgParam;
import cn.stylefeng.guns.modular.transport.model.result.TDispatchResult;
import cn.stylefeng.guns.modular.transport.model.result.TransportMsgResult;
import cn.stylefeng.guns.modular.transport.service.TDispatchService;
import cn.stylefeng.guns.modular.transport.service.TransportMsgService;
import cn.stylefeng.guns.sys.modular.system.service.UserService;
import cn.stylefeng.roses.core.util.ToolUtil;
import org.apache.xmlbeans.impl.xb.xsdschema.Public;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.ResponseBody;

import java.text.SimpleDateFormat;
import java.util.ArrayList;
import java.util.Date;
import java.util.List;

@Controller
@RequestMapping("/datavPro")
public class datavProController {
    @Autowired
    private HxStorageOutService hxStorageOutService;
    @Autowired
    private HxStoragePutService hxStoragePutService;
    @Autowired
    private OrderTransportService orderTransportService;
    @Autowired
    private UserService userService;
    @Autowired
    private BasicWarehouseService basicWarehouseService;
    @Autowired
    private HxStorageOffShelfService HxStorageOffShelfService;
    @Autowired
    private HxStoragePutDetailedService hxStoragePutDetailedService;
    @Autowired
    private HxStorageOutDetailedService hxStorageOutDetailedService;
    @Autowired
    private HxStorageStockService hxStorageStockService;
    @Autowired
    private TransportMsgService transportMsgService;
    @Autowired
    private TDispatchService tDispatchService;

    /**
     * 查询仓库list
     * @param
     * @return
     */
    @ResponseBody
    @RequestMapping("/getWarehouselist")
    public List<BasicWarehouseResult> getWarehouselist() {
        BasicWarehouseParam basicWarehouseParam = new BasicWarehouseParam();
        basicWarehouseParam.setWarehouseTypes("零售");
        List<BasicWarehouseResult> list = basicWarehouseService.findListBySpec(basicWarehouseParam ,null,null);
        //System.out.println(list);
        return list;
    }

    /**
     * 查询作业进度
     */
    @ResponseBody
    @RequestMapping("/gettaskjindu")
    public List<datavProResult> gettaskjindu(datavProResult  datavProResult) {
        List<datavProResult> list = hxStorageOutService.find(datavProResult);
        //System.out.println(list);
        return list;
    }

    /*
        @ResponseBody
    @RequestMapping("/gettaskjindu")
    public List<datavProResult> gettaskjindu(datavProResult datavProResult) {
        // 获取当前日期
        Date currentDate = new Date();
        // 创建SimpleDateFormat对象，并设置日期格式
        SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd");
        String formattedDate = sdf.format(currentDate);

        datavProResult.setPeisong_time(formattedDate);
        List<datavProResult> list = hxStorageOutService.find(datavProResult);
        // 返回查询结果列表
        return list;
    }
    * */

    /**
     * 查询待调
     * @param storeProResult
     * @return
     */
    @ResponseBody
    @RequestMapping("/findtransport")
    public List<storeProResult> findtransport(storeProResult  storeProResult) {
        storeProResult.setTstate("待调");
        List<storeProResult> list = hxStorageOutService.find1(storeProResult);
        //System.out.println(list);
        return list;
    }
    /**
     * 等待装车车辆
     * @param
     * @return
     */
    @ResponseBody
    @RequestMapping("/findtransportCar")
    public List<TransportMsgResult> findtransportCar(BasicWarehouseParam basicWarehouseParam ) {
        TransportMsgParam transportMsgParam = new TransportMsgParam();
        transportMsgParam.setStatus("到仓签到");
        BasicWarehouse byId = basicWarehouseService.getById(basicWarehouseParam.getId());
        List<TransportMsgResult> list = this.transportMsgService.finddriverSigninPageBySpec2(transportMsgParam,null,(long)byId.getWarehouseOperateId());
//        System.out.println("等待装车的："+list);
        return list;
    }

    /**
     * 卸车
     * @param
     * @return
     */
    @ResponseBody
    @RequestMapping("/findtransportUnCar")
    public List<TransportMsgResult> findtransportUnCar(BasicWarehouseParam basicWarehouseParam ) {
        TransportMsgParam transportMsgParam = new TransportMsgParam();
        transportMsgParam.setStatus("送达");
        BasicWarehouse byId = basicWarehouseService.getById(basicWarehouseParam.getId());
        List<TransportMsgResult> list = this.transportMsgService.finddriverSigninPageBySpec2(transportMsgParam,null,(long)byId.getWarehouseOperateId());
//        System.out.println("等待装车的："+list);
        return list;
    }


    /**
     * 查询装车进度列表
     */
    @ResponseBody
    @RequestMapping("/zhuangchejindu")
    public List<TDispatchResult> zhuangchejindu(BasicWarehouseParam basicWarehouseParam ) {
        TDispatchParam tDispatchParam = new TDispatchParam();
        BasicWarehouse byId = basicWarehouseService.getById(basicWarehouseParam.getId());
        List<TDispatchResult> list = this.tDispatchService.findHxzhuangchejindu(tDispatchParam,null,(long)byId.getWarehouseOperateId());
        //System.out.println(list);
        return list;
    }

    /**
     *查询出库方位
     * @param chukuPositionResult
     * @return
     */
    @ResponseBody
    @RequestMapping("/findchukuposition")
    public List<chukuPositionResult> findchukuposition(chukuPositionResult  chukuPositionResult) {
        List<chukuPositionResult> list = hxStorageOutService.findchukuposition(chukuPositionResult);
        //System.out.println(list);
        return list;
    }


    /**
     *拣货统计,作业量统计
     * @param chukuPositionResult
     * @return
     */
    @ResponseBody
    @RequestMapping("/findjihuoliang")
    public List<chukuPositionResult> findjihuoliang(chukuPositionResult  chukuPositionResult) {
        List<chukuPositionResult> list = hxStorageOutService.findjihuoliang(chukuPositionResult);
        //System.out.println(list);
        return list;
    }

    /**
     *查询入库方位
     * @param rukuPositionResult
     * @return
     */
    @ResponseBody
    @RequestMapping("/findrukuposition")
    public List<rukuPositionResult> findrukuposition(rukuPositionResult  rukuPositionResult) {
        List<rukuPositionResult> list = hxStoragePutService.findrukuposition(rukuPositionResult);
        //System.out.println(list);
        return list;
    }
    /**
     *查询仓库存储容量信息任务详情
     */
    @ResponseBody
    @RequestMapping("/findCcCapacityData")
    public List<HxStorageStockResult> findCccapacityData(HxStorageStockResult hxStorageStockResult) {
        List<HxStorageStockResult> list =hxStorageStockService.findCccapacityData(hxStorageStockResult);
        //System.out.println(list);
        return list;
    }

    /**
     *查询上架任务详情
     */
    @ResponseBody
    @RequestMapping("/findShangjiaData")
    public List<HxStoragePutDetailedResult> findShangjiaData(HxStoragePutDetailedResult hxStoragePutDetailedResult) {
        hxStoragePutDetailedResult.setPutState("已上架");
        List<HxStoragePutDetailedResult> list = hxStoragePutDetailedService.findShangjiaData(hxStoragePutDetailedResult);
        //System.out.println(list);
        return list;
    }

    /**
     *查询下架任务详情
     */
    @ResponseBody
    @RequestMapping("/findxiajia")
    public List<HxStorageOffShelfResult> findxiajia(HxStorageOffShelfResult  hxStorageOffShelfResult) {
        hxStorageOffShelfResult.setStatus("已完成");
        // 获取当天时间
        SimpleDateFormat formatter = new SimpleDateFormat("yyyy-MM-dd");
        String currentDate = formatter.format(new Date());
        hxStorageOffShelfResult.setTimeInterval("'"+currentDate+"' and '"+currentDate+"'");

        List<HxStorageOffShelfResult> list = HxStorageOffShelfService.findxiajia(hxStorageOffShelfResult);
        //System.out.println(list);
        return list;
    }

    /**
     *查询拣货任务详情
     */
    @ResponseBody
    @RequestMapping("/findJjianhuoData")
    public List<HxStorageOutResult> findJjianhuoData(HxStorageOutResult hxStorageOutResult) {
        String[] StorageState={"待复核","复核中","已完成"};
        hxStorageOutResult.setStorageState1(StorageState);
        List<HxStorageOutResult> list = hxStorageOutService.findJjianhuoData(hxStorageOutResult);
        //System.out.println(list);
        return list;
    }

    /**
     *查询质检任务详情
     */
    @ResponseBody
    @RequestMapping("/findZhijianData")
    public List<HxStorageOutResult> findZhijianData(HxStorageOutResult hxStorageOutResult) {
        hxStorageOutResult.setStorageState("已完成");
        // 获取当天时间
        SimpleDateFormat formatter = new SimpleDateFormat("yyyy-MM-dd");
        String currentDate = formatter.format(new Date());
        hxStorageOutResult.setTimeInterval("'"+currentDate+"' and '"+currentDate+"'");

        List<HxStorageOutResult> list = hxStorageOutService.findZhijianData(hxStorageOutResult);
        //System.out.println(list);
        return list;
    }

    /**
     *查询等待装车门店任务详情
     */
    @ResponseBody
    @RequestMapping("/findDdPretendCarData")
    public List<HxStorageOutResult> findDdPretendCarData(HxStorageOutResult hxStorageOutResult) {
        List<HxStorageOutResult> list = hxStorageOutService.findDdPretendCarData(hxStorageOutResult);
        //System.out.println(list);
        return list;
    }

    /**
     *查询作业进度
     */
    @ResponseBody
    @RequestMapping("/findzuoye")
    public List<HxStorageOutResult> findzuoye(HxStorageOutResult HxStorageOutResult) {
        List<HxStorageOutResult> list = hxStorageOutService.findzuoye(HxStorageOutResult);
        //System.out.println(list);
        return list;
    }

    /**
     * 查询上架情况
     * @param hxStoragePutDetailedParam
     * @return
     */
    @ResponseBody
    @RequestMapping("/findShelvesData")
    public List<HxStoragePutDetailedResult> findShelvesData(HxStoragePutDetailedParam hxStoragePutDetailedParam){

        // 获取当天时间
        SimpleDateFormat formatter = new SimpleDateFormat("yyyy-MM-dd");
        String currentDate = formatter.format(new Date());
        hxStoragePutDetailedParam.setTimeInterval("'"+currentDate+"' and '"+currentDate+"'");

        List<HxStoragePutDetailedResult> shelvesData = hxStoragePutDetailedService.findShelvesData(hxStoragePutDetailedParam);
        return shelvesData;
    }
}
